package cn.ekuma.epos.order;

import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import javax.swing.JTextPane;

import com.openbravo.bean.erp.viewbean.FindOrdersInfo;
import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppLocal;
import java.awt.Dimension;
import javax.swing.border.TitledBorder;

public class JOrderInfoViewPanel extends JPanel {
	private JTextField orderid;
	private JTextField ordertype;
	private JTextField date;
	private JTextField customer;
	private JTextField user;
	private JTextField totalcash;
	private JTextField priceRate;
	private JTextField referncePerson;
	private JTextField orderState;
	private JTextField location;
	private JTextField address2;
	private JTextPane notes;
	private JTextField debt;

	/**
	 * Create the panel.
	 */
	public JOrderInfoViewPanel() {
		initComponents();
	}
	private void initComponents() {
		setPreferredSize(new Dimension(473, 326));
		setLayout(null);
		
		JLabel label = new JLabel(AppLocal.getIntString("label.orderid"));
		label.setBounds(10, 10, 54, 15);
		add(label);
		
		orderid = new JTextField();
		orderid.setEnabled(false);
		orderid.setBounds(84, 7, 148, 21);
		add(orderid);
		orderid.setColumns(10);
		
		JLabel label_1 = new JLabel(AppLocal.getIntString("label.ordertype"));
		label_1.setBounds(247, 10, 54, 15);
		add(label_1);
		
		ordertype = new JTextField();
		ordertype.setEnabled(false);
		ordertype.setBounds(311, 8, 94, 18);
		add(ordertype);
		ordertype.setColumns(10);
		
		JCheckBox bearing = new JCheckBox(AppLocal.getIntString("label.ordertypedialog.bearing"));
		bearing.setEnabled(false);
		bearing.setBounds(411, 6, 78, 19);
		add(bearing);
		
		JLabel label_2 = new JLabel(AppLocal.getIntString("label.date"));
		label_2.setBounds(10, 43, 54, 15);
		add(label_2);
		
		date = new JTextField();
		date.setEnabled(false);
		date.setBounds(84, 40, 148, 21);
		add(date);
		date.setColumns(10);
		
		JLabel label_3 = new JLabel(AppLocal.getIntString("label.customer"));
		label_3.setBounds(10, 76, 54, 15);
		add(label_3);
		
		customer = new JTextField();
		customer.setEnabled(false);
		customer.setBounds(84, 73, 228, 21);
		add(customer);
		customer.setColumns(10);
		
		JLabel label_4 = new JLabel(AppLocal.getIntString("Menu.Users"));
		label_4.setBounds(247, 43, 54, 15);
		add(label_4);
		
		user = new JTextField();
		user.setEnabled(false);
		user.setBounds(311, 40, 94, 21);
		add(user);
		user.setColumns(10);
		
		JLabel label_5 = new JLabel(AppLocal.getIntString("label.totalcash"));
		label_5.setBounds(10, 104, 54, 15);
		add(label_5);
		
		totalcash = new JTextField();
		totalcash.setEnabled(false);
		totalcash.setBounds(84, 101, 153, 21);
		add(totalcash);
		totalcash.setColumns(10);
		
		JLabel label_6 = new JLabel(AppLocal.getIntString("label.orderStates"));
		label_6.setBounds(247, 132, 54, 15);
		add(label_6);
		
		priceRate = new JTextField();
		priceRate.setEnabled(false);
		priceRate.setBounds(311, 101, 94, 21);
		add(priceRate);
		priceRate.setColumns(10);
		
		JLabel label_7 = new JLabel(AppLocal.getIntString("label.referncePerson"));
		label_7.setBounds(10, 132, 54, 15);
		add(label_7);
		
		referncePerson = new JTextField();
		referncePerson.setEnabled(false);
		referncePerson.setBounds(84, 129, 153, 21);
		add(referncePerson);
		referncePerson.setColumns(10);
		
		JLabel label_8 = new JLabel(AppLocal.getIntString("label.priceRate"));
		label_8.setBounds(247, 104, 54, 15);
		add(label_8);
		
		orderState = new JTextField();
		orderState.setEnabled(false);
		orderState.setBounds(311, 129, 94, 21);
		add(orderState);
		orderState.setColumns(10);
		
		JLabel label_9 = new JLabel(AppLocal.getIntString("label.location"));
		label_9.setBounds(10, 160, 54, 15);
		add(label_9);
		
		location = new JTextField();
		location.setEnabled(false);
		location.setBounds(84, 157, 153, 21);
		add(location);
		location.setColumns(10);
		
		JLabel label_10 = new JLabel(AppLocal.getIntString("label.address2"));
		label_10.setBounds(247, 160, 54, 15);
		add(label_10);
		
		address2 = new JTextField();
		address2.setEnabled(false);
		address2.setBounds(311, 157, 94, 21);
		add(address2);
		address2.setColumns(10);
		
		notes = new JTextPane();
		notes.setBorder(new TitledBorder(null, AppLocal.getIntString("label.notes"), TitledBorder.LEADING, TitledBorder.TOP, null, null));
		notes.setEnabled(false);
		notes.setBounds(10, 208, 413, 97);
		add(notes);
		
		debt = new JTextField();
		debt.setEditable(false);
		debt.setBounds(311, 73, 94, 21);
		add(debt);
		debt.setColumns(10);
	}
	
	public void updateUI(FindOrdersInfo obj){
		if(obj!=null){
			orderid.setText(obj.getOrderId());
			ordertype.setText(obj.getDefineType());
			date.setText(Formats.TIMESTAMP.formatValue(obj.getDate()));
			customer.setText(obj.getCustomer());
			user.setText(obj.getName());
			totalcash.setText(Formats.CURRENCY.formatValue(obj.getTotalPrice()));
			priceRate.setText(Formats.PERCENT.formatValue(obj.getM_dPriceRate()));
			referncePerson.setText(obj.getM_sResponse());
			orderState.setText(obj.getCurrentState());
			location.setText(obj.getLocation());
			address2.setText(obj.getLocationRef1());
			notes.setText(obj.getMemo());
			debt.setText(Formats.CURRENCY.formatValue(obj.getDebt()));
		}else{
			orderid.setText(null);
			ordertype.setText(null);
			date.setText(null);
			customer.setText(null);
			user.setText(null);
			totalcash.setText(null);
			priceRate.setText(null);
			referncePerson.setText(null);
			orderState.setText(null);
			location.setText(null);
			address2.setText(null);
			notes.setText(null);
			debt.setText(null);
		}
	}
}
